#ifndef _DECODE_H264_H_
#define _DECODE_H264_H_

#include "config.hpp"
#include "motion_detect.hpp"
#include "muxer_mp4.hpp"
#include "ringbuffer.hpp"
#include <cstring>
#include <iostream>
#include <thread>

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/frame.h>
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
}

class decode_h264 {
private:
    std::string ip;
    bool running;
    std::thread handle;
    ringbuffer* rbuf;
    motion_detect mdet;
    muxer_mp4* mux;
    std::vector<std::vector<int>> shields;

public:
    decode_h264();
    decode_h264(ringbuffer* ringbuffer, std::string ip);
    ~decode_h264();

    int set(ringbuffer* ringbuffer, std::string ip, std::vector<std::vector<int>> regions);
    void thread();
    void start();
    void stop();
    void mux_set(muxer_mp4* mux);
    void rect_shield(AVFrame* frame, int x1, int y1, int w, int h);
    void save_shield(AVFrame* frame, std::string filename);
    void msleep(int ms);
};

#endif